﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WeChat.Common;
using WeChat.Common2;
using WeChat.HyfPay.Hyflib;
using WeChat.JsSDK.lib;
namespace WeChat.HyfPay
{
    /// <summary>
    /// PayPage1 的摘要说明
    /// </summary>
    public class PayPage1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            //判断请求头，是微信app还是支付宝app提交的请求
            string agent = context.Request.Headers["User-Agent"].ToString();
            string url = "";
            string order_No = context.Request.QueryString["order_No"].ToString();
            string amount = context.Request.QueryString["amount"].ToString();
            string cardID = context.Request.QueryString["cardID"].ToString();
            //如果请求头判断为微信app请求则调用微信二维码下单接口
            if (agent.IndexOf("MicroMessenger") > -1)
            {
               // url = HyfPayApi.getResult("011", order_No, amount, cardID);
            }
            //如果请求头判断为支付宝app请求则调用支付宝二维码下单接口
            else if (agent.IndexOf("AlipayClient") > -1)
            {
             //   url = HyfPayApi.getResult("009", order_No, amount, cardID);
            }

            ApplicationLog.Write("获取二维码返回值并重定向url：" + url);
            context.Response.ContentType = "text/plain";
            context.Response.Redirect(url);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}